package com.demo.service.impl;

import com.demo.dto.ClassesDTO;
import com.demo.dto.ClassesPageQueryDTO;
import com.demo.mapper.ClassesMapper;
import com.demo.pojo.Classes;
import com.demo.pojo.Department;
import com.demo.result.PageResult;
import com.demo.service.ClassesService;
import com.demo.vo.ClassesVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassesServiceImpl implements ClassesService {
    @Autowired
    ClassesMapper classesMapper;

    @Override
    public void save(ClassesDTO classesDTO) {
        System.out.println(classesDTO);
        Classes classes=new Classes();
        BeanUtils.copyProperties(classesDTO,classes);
        classesMapper.addClasses(classes);
    }

    @Override
    public void delete(String[] classIDs) {
        for(String classID:classIDs){
            classesMapper.delete(classID);
        }
    }

    @Override
    public void deleteById(String classID) {
        classesMapper.delete(classID);
    }

    @Override
    public void update(ClassesDTO classesDTO) {
        classesMapper.update(classesDTO);
    }

    @Override
    public PageResult pageQuery(ClassesPageQueryDTO classesPageQueryDTO) {
        System.out.println(classesPageQueryDTO);
        PageHelper.startPage(classesPageQueryDTO.getPage(), classesPageQueryDTO.getPageSize());
        Page<ClassesVO> page = classesMapper.pageQuery(classesPageQueryDTO);
        long total = page.getTotal();
        List<ClassesVO> records = page.getResult();
        System.out.println(total+"22222222");
        System.out.println(records+"!!!");
        return new PageResult(total, records);
    }
}
